﻿///<reference path="../../lib/lt_tsbb.d.ts"/>
///<reference path="./PointView.ts"/>
///<reference path="./PathView.ts"/>
namespace Flow.views
{
    class BTree
    {
        blockid: number;
        subB: BTree[] = [];
        subInP: BTree[] = [];
        //width: number = 0;
        //height: number = 0;
        FillFlow(player: lighttool.tsbb.bbplayer, freeblock: { [id: number]: number })
        {
            var b = player.getBlock(this.blockid);
            if (b == null)
                return;
            for (var i = 0; i < b.exits.length; i++)
            {
                var next = b.exits[i];
                if (next >= 0 && freeblock[next] != undefined)
                {
                    delete freeblock[next];
                    var st = new BTree();
                    st.blockid = next;
                    this.subB.push(st);

                    //处理入参，by 李湛
                    //let block = player.getBlock(next);
                    //if (block.inparams != undefined && block.inparams.length > 0) {
                    //    for (let i = 0; i < block.inparams.length; i++) {
                    //        let st = new BTree();
                    //        st.blockid = block.inparams[i].blockID;
                    //        this.subB.push(st);
                    //    }
                    //}
                    st.FillFlow(player, freeblock);
                }
            }
        }
        FillParam(player: lighttool.tsbb.bbplayer, freeblock: { [id: number]: number })
        {
            var b = player.getBlock(this.blockid);
            if (b == null)
                return;
            if (b.inparams != undefined)
            {
                for (var i = 0; i < b.inparams.length; i++)
                {
                    var last = b.inparams[i].blockID;
                    if (last >= 0 && freeblock[last] != undefined)
                    {
                        delete freeblock[last];
                        var st = new BTree();
                        st.blockid = last;
                        this.subInP.push(st);
                        st.FillParam(player, freeblock);
                    }
                }
            }
            //遍历
            for (var i = 0; i < this.subB.length; i++)
            {
                this.subB[i].FillParam(player, freeblock);
            }
        }
        SetBlockPos(player: PlayerView, x: number = 0, y: number = 0): number
        {

            for (var i = 0; i < this.subInP.length; i++)
            {
                x = Math.max(x, this.subInP[i].SetBlockPos(player, x, y) + 100);
            }
            //先摆参数再摆我
            var block = player.bplayer.getBlock(this.blockid);
            block.x = x;
            block.y = y;

            x += player.getBlockWidth(this.blockid);

            //再摆孩子,要让孩子右对齐
            var maxparamwidth = 0;
            for (var i = 0; i < this.subB.length; i++)
            {
                maxparamwidth = Math.max(this.subB[i].getParamWidth(player), maxparamwidth);
            }
            for (var i = 0; i < this.subB.length; i++)
            {
                var w = this.subB[i].getParamWidth(player);
                this.subB[i].SetBlockPos(player, x + maxparamwidth - w + 100, y);
                y += this.subB[i].getHeight(player) + 50;
            }
            return x;//返回当前块摆下之后的x值
        }
        getParamWidth(player: PlayerView): number
        {
            var width = 0;
            for (var i = 0; i < this.subInP.length; i++)
            {
                var sw = this.subInP[i].getParamWidth(player) + 100 + player.getBlockWidth(this.subInP[i].blockid);
                width = Math.max(sw, width);
            }
            //this.width = Math.max(this.width, width);
            return width;
        }
        getHeight(player: PlayerView): number
        {
            //要考虑参数高度
            var height = 0;
            for (var i = 0; i < this.subB.length; i++)
            {
                height += this.subB[i].getHeight(player);
                if (i > 0)
                    height += 50;
            }
            var height2 = player.getBlockHeight(this.blockid);
            var height3 = 0;
            for (var i = 0; i < this.subInP.length; i++)
            {
                height3 += this.subInP[i].getHeight(player);
                if (i > 0)
                    height3 += 50;
            }
            height = Math.max(height, height2);
            height = Math.max(height, height3);
            //this.height = Math.max(this.height, height);
            return height;
        }
    }
    export class PlayerView
    {
        private background: HTMLElement;
        public blockViews: Array<BlockView> = [];
        bplayer: lighttool.tsbb.bbplayer;
        private pathArr: Array<PathView> = [];
        private svg: SVGSVGElement;
        private x: number = 0;
        private y: number = 0;

        //用来移动界面
        private BoolMoveBackGround = false;
        private MoveX = 0;
        private MoveY = 0;
        private bgX = 0;
        private bgY = 0;

        //用来移动块
        private myBlockView: BlockView = null;
        private BoolMoveBlockView = false;
        private rememberX = 0;
        private rememberY = 0;

        //svg界面与html界面偏移
        private SVGoffSetX = 100;
        private SVGoffSetY = 330;

        constructor(background: HTMLElement)
        {
            this.background = background;
        }

        private mouseDown(e: MouseEvent) {
            var IsBlock = false;
            if (this.blockViews) {
                for (let i: number = 0; i < this.blockViews.length; i++) {
                    if (this.blockViews[i].block.x < e.x - this.SVGoffSetX + this.background.scrollLeft && this.blockViews[i].block.x + this.blockViews[i].width > e.x - this.SVGoffSetX + this.background.scrollLeft
                        && this.blockViews[i].block.y < e.y - this.SVGoffSetY + this.background.scrollTop && this.blockViews[i].block.y + this.blockViews[i].height > e.y - this.SVGoffSetY + this.background.scrollTop) {
                        IsBlock = true;
                        this.myBlockView = this.blockViews[i];
                        break;
                    }
                }
            }
            if (IsBlock) {
                this.BoolMoveBlockView = true;
                this.rememberX = this.myBlockView.block.x;
                this.rememberY = this.myBlockView.block.y;
                this.MoveX = e.x;
                this.MoveY = e.y;
            } else {
                this.BoolMoveBackGround = true;
                this.bgX = this.background.scrollLeft;
                this.bgY = this.background.scrollTop;
                this.MoveX = e.x;
                this.MoveY = e.y;
            }
        }

        private mousemove(e: MouseEvent)
        {
            //if (this.blockViews)
            //{
            //    for (let i: number = 0; i < this.blockViews.length; i++)
            //    {
            //        this.blockViews[i].onmousemove(e);
            //        //this.blockViews[i].updateBloock();
                    
            //    }
            //}
            //if (this.pathArr)
            //{
            //    for (let i: number = 0; i < this.pathArr.length; i++)
            //    {
            //        this.pathArr[i].update();
            //    }
            //}

            if (this.BoolMoveBlockView) {
                this.myBlockView.block.x = this.rememberX + e.x - this.MoveX;
                this.myBlockView.block.y = this.rememberY + e.y - this.MoveY; 
            }
            else if (this.BoolMoveBackGround) {
                this.background.scrollLeft = this.bgX + this.MoveX - e.x;
                this.background.scrollTop = this.bgX + this.MoveY - e.y;
                let width = Math.max(this.background.clientWidth, this.background.scrollLeft);
                let height = Math.max(this.background.clientHeight, this.background.scrollTop);
                this.background.setAttribute("width", width + "");
                this.background.setAttribute("height", height + "");
            }
        }
        private mouseup(e: MouseEvent)
        {
            this.BoolMoveBackGround = false;
            this.BoolMoveBlockView = false;
            //if (this.blockViews)
            //{
            //    for (let i: number = 0; i < this.blockViews.length; i++)
            //    {
            //        this.blockViews[i].onmouseup(e);
            //        //this.blockViews[i].updateBloock();
            //    }
            //}
            //if (this.pathArr)
            //{
            //    for (let i: number = 0; i < this.pathArr.length; i++)
            //    {
            //        this.pathArr[i].update();
            //    }
            //}
        }
        private debugPlayer(time: number)
        {
            var token = setInterval(() =>
            {
                this.bplayer.update();
                if (this.bplayer.isPlayerRun()) {
                    for (let i: number = 0; i < this.blockViews.length; i++) {
                        if (this.blockViews[i].block == this.bplayer.getCurBlock()) {
                            this.blockViews[i].bgFill = "green";
                            this.blockViews[i].class = "loading";
                            this.blockViews[i].updateBloock();
                        } else {
                            this.blockViews[i].bgFill = "blue";
                            this.blockViews[i].class = "";
                            this.blockViews[i].updateBloock();
                        }
                    }
                } else {
                    for (let i: number = 0; i < this.blockViews.length; i++) {
                        if (this.blockViews[i].block == this.bplayer.getCurBlock()) {
                            this.blockViews[i].bgFill = "green";
                            this.blockViews[i].class = "loading";
                            this.blockViews[i].updateBloock();
                        } else {
                            this.blockViews[i].bgFill = "blue";
                            this.blockViews[i].class = "";
                            this.blockViews[i].updateBloock();
                        }
                    }
                }
                //if (this.bplayer.isPlayerEnd()) {
                //    alert("done");
                //    for (let i: number = 0; i < this.blockViews.length; i++) {
                //        this.blockViews[i].bgFill = "blue";
                //        this.blockViews[i].class = "";
                //        this.blockViews[i].updateBloock();
                //    }
                //    clearTimeout(token);
                //}
                if (this.myBlockView)
                {
                    this.myBlockView.UpdateScroll(this.background);
                    this.myBlockView.updateBloock();
                }
                if (this.pathArr) {
                    for (let i: number = 0; i < this.pathArr.length; i++) {
                        this.pathArr[i].update();
                    }
                }
            }, time);
        }
        //返回blockView
        private getBlock(blockId: number): BlockView
        {
            let i: number = 0;
            while (i < this.blockViews.length)
            {
                if (this.blockViews[i].block.id == blockId)
                {
                    return this.blockViews[i];
                }
                i++;
            }
        }

        //初始化流程图
        public initFlow(bplayer: lighttool.tsbb.bbplayer)
        {
            //创建画布
            this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg") as SVGSVGElement;
            this.svg.addEventListener("mousedown", this.mouseDown.bind(this));
            this.svg.addEventListener("mousemove", this.mousemove.bind(this));
            this.svg.addEventListener("mouseup", this.mouseup.bind(this));
            this.bplayer = bplayer;
            this.background.appendChild(this.svg);
            this.background.style.position = "absolute";
            this.background.style.overflow = "auto";
            this.svg.setAttribute("width", "1717");
            this.svg.setAttribute("height", "700");
            //this.svg.style.position = "absolute";
            //this.svg.style.overflow = "auto";

            this.update();
            //this.sortOrder();
          
            //this.bplayer.start(bplayer.getBeginBlock().id);
            this.debugPlayer(50);
        }

        public update()
        {
            //删除之前所有的block 
            this.blockViews = [];

            var clsarray = [];
            var c = this.svg.childNodes;
            if (c != null) {
                for (var i = 0; i < c.length; i++) {
                    clsarray.push(c[i]);
                }
                for (var i = 0; i < clsarray.length; i++) {
                    this.svg.removeChild(clsarray[i]);
                }
            }

            //this.svg.innerHTML = "";
            //重新来过
            //获取所有的block 并创建
            let blockIds: number[] = this.bplayer.getAllBlockId();
            for (let i: number = 0; i < blockIds.length; i++)
            {
                let block: lighttool.tsbb.bBlock = this.bplayer.getBlock(blockIds[i]);
                let bView = new BlockView(this.svg);
                bView.initBlock(block);
                this.blockViews.push(bView);
            }
            this.glineBlock();
        }
        public sortOrder()
        {
            //自由块，未连接在流程中的块
            var _freeblock: number[] = this.bplayer.getAllBlockId();
            var freeblock: { [id: number]: number } = {};
            for (var i = 0; i < _freeblock.length; i++)
            {
                freeblock[_freeblock[i]] = 1;
            }

            var y = 0;
            {
                //用beginblock 作为开头
                var tree = new BTree();
                tree.blockid = this.bplayer.getBeginBlock().id;
                delete freeblock[tree.blockid];

                //先做流程关系
                tree.FillFlow(this.bplayer, freeblock);
                tree.FillParam(this.bplayer, freeblock);
                //fillBlockTree
                //之后还有参数关系
                //等待线画出来之后，再调试参数关系排序比较容易

                //改变关联块的位置
                tree.SetBlockPos(this, 0, y);
                y += tree.getHeight(this) + 50;
            }
            //自由块 摆在下面

            for (var key in freeblock)
            {
                var tree = new BTree();
                tree.blockid = parseInt(key);
                delete freeblock[tree.blockid];
                tree.FillFlow(this.bplayer, freeblock);
                tree.SetBlockPos(this, 0, y);
                y += tree.getHeight(this) + 50;
            }

            //this.update();//排完序，自动处理
            if (this.blockViews)
            {
                for (let i: number = 0; i < this.blockViews.length; i++)
                {
                    this.blockViews[i].updateBloock();
                }
            }

            if (this.pathArr)
            {
                for (let i: number = 0; i < this.pathArr.length; i++)
                {
                    this.pathArr[i].update();
                }
            }
            this.svg.setAttribute("width", this.getMaxWidth() + 500 + "");
            this.svg.setAttribute("height", y + "");
            
        }
        private glineBlock()
        {
            for (let i: number = 0; i < this.blockViews.length; i++)
            {
                let blockView = this.blockViews[i];
                let block = blockView.block;
                for (let n: number = 0; n < block.exits.length; n++)
                {
                    if (block.exits[n] == -1) continue;
                    let exit = blockView.getPoint(pointType.OUT_FLOW, n);
                    if (block.exits[n] == undefined) continue;
                    let bView = this.getBlock(block.exits[n]);
                    let entry = bView.getPoint(pointType.IN_FLOW, 0);
                    exit.setLinkType(linkType.LINK);
                    entry.setLinkType(linkType.LINK);
                    let path: PathView = new PathView(this.svg);
                    path.initPath(exit, entry);
                    this.pathArr.push(path);
                }
                if (blockView.block.inparams)
                {
                    for (let n: number = 0; n < block.inparams.length; n++)
                    {
                        let inParam = blockView.getPoint(pointType.IN_PARAM, n);
                        if (block.inparams[n].blockID == -1)
                        {
                            if (block.inparams[n].constValue) {
                                inParam.setTextValue(block.inparams[n].constValue+"");
                            }
                            continue;
                        }
                        inParam.setLinkType(linkType.LINK);
                        inParam.deleteInput();
                        let bView = this.getBlock(block.inparams[n].blockID);
                        //有bug获取不到正确的出参
                        let outParam = bView.getPoint(pointType.OUT_PARAM, block.inparams[n].paramOutIndex);
                        outParam.setLinkType(linkType.LINK);
                        let path: PathView = new PathView(this.svg);
                        path.initPath(outParam, inParam);
                        this.pathArr.push(path);
                    }
                }
            }
        }
        public getBlockHeight(blockId: number): number
        {
            return this.getBlock(blockId).height;
        }
        public getBlockWidth(blockId: number): number
        {
            return this.getBlock(blockId).width;
        }
        private getMaxWidth(): number
        {
            let x: number=0;
            this.blockViews
            for (let i: number = 0; i < this.blockViews.length; i++)
            {
                x = Math.max(x, this.blockViews[i].block.x);
            }
            return x;
        }
    }
    export class BlockView
    {
        public blockId: number;
        public blockG: SVGGElement;
        public bgFill: string = "blue";
        public class: string = "";
        private background: SVGSVGElement;  //背景画布
        private blockRect: SVGRectElement;  //流程方块
        private titleRect: SVGRectElement;  //标题背景方块
        private titleText: SVGTextElement;  //标题文字
        private pointArr: Array<Point> = [];  //锚点数组
        private pointXArr: Array<number> = [];
        private pointyArr: Array<number> = [];
        public block: lighttool.tsbb.bBlock;   //block
        private textPoin: { x: number, y: number } = { x: 70, y: 20 };
        private titlePoin: { x: number, y: number } = { x: 2, y: 0 };
        private moveX: number;
        private moveY: number;
        public height: number;
        public width: number;

        isMouse: boolean = false;//不可拖动

        constructor(background: SVGSVGElement)
        {
            this.background = background;
            this.blockRect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
            this.titleRect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
            this.titleText = document.createElementNS("http://www.w3.org/2000/svg", "text");
            this.blockG = document.createElementNS("http://www.w3.org/2000/svg", "g");

            this.blockG.appendChild(this.blockRect);
            this.blockG.appendChild(this.titleRect);
            this.blockG.appendChild(this.titleText);
            this.background.appendChild(this.blockG);
            this.blockG.addEventListener("mousedown", this.onmousedown.bind(this));

            //流程块样式
            this.blockRect.setAttribute("width", "200");
            this.blockRect.setAttribute("stroke-width", "3");
            this.blockRect.setAttribute("fill-opacity", "0.1");
            this.blockRect.setAttribute("stroke-opacity", "0.9");
            this.blockRect.style.fill = "blue";
            this.blockRect.style.stroke = "pink";
            //标题块样式
            this.titleRect.setAttribute("width", "195");
            this.titleRect.setAttribute("height", "25");
            this.titleRect.setAttribute("x", "2.5");
            this.titleRect.setAttribute("y", "2");
            this.titleRect.style.fill = "#fbf8f7";
            this.titleRect.style.stroke = "#fbf8f7";
            this.titlePoin = { x: 2.5, y: 2 };
            //标题文字
            this.titleText.setAttribute("width", "195");
            this.titleText.setAttribute("x", "70");
            this.titleText.setAttribute("y", "20");
            this.titleText.setAttribute("fill", "black");
            this.titleText.setAttribute("font-size", "18pt");
            this.textPoin = { x: 70, y: 20 };

        }

        public initBlock(block: lighttool.tsbb.bBlock)
        {
            this.block = block;
            this.blockId = block.id;
            let inParams;
            let outParams;
            let outHeight: number = 0;
            let inHeight: number = 0;
            let lenght: number = 30;

            if (block.type == lighttool.tsbb.bBlockType.FlowBlock_Begin)//入口特殊的(无入口)
            {
                //无desc
                let entrance = new Point(this.blockG);
                entrance.initPoint(this.block.id, 0, pointType.OUT_FLOW, linkType.NO_LINK, 175, lenght);
                this.pointArr.push(entrance);
                this.pointXArr.push(175);
                this.pointyArr.push(lenght);
                inHeight += 30;

                this.blockRect.setAttribute("width", "200");
                this.blockRect.setAttribute("stroke-width", "3");
                this.blockRect.setAttribute("fill-opacity", "0.1");
                this.blockRect.setAttribute("stroke-opacity", "0.9");
                this.blockRect.style.fill = "blue";
                this.blockRect.style.stroke = "pink";
            }
            else if (block.type == lighttool.tsbb.bBlockType.FlowBlock_End)//出口特殊的(无出口)
            {
                //无desc
                let exit = new Point(this.blockG);
                exit.initPoint(this.block.id, 0, pointType.IN_FLOW, linkType.NO_LINK, 5, lenght);
                this.pointArr.push(exit);
                this.pointXArr.push(5);
                this.pointyArr.push(lenght);
                outHeight += 30;
            }
            else if (block.type == lighttool.tsbb.bBlockType.FlowBlock_User)
            {
                //必须有一个入口
                //可能有1或多个出口
                let entrance = new Point(this.blockG);
                entrance.initPoint(this.block.id, 0, pointType.IN_FLOW, linkType.NO_LINK, 5, lenght);
                this.pointArr.push(entrance);
                this.pointXArr.push(5);
                this.pointyArr.push(lenght);
                inHeight = 30;
                inParams = block.action.desc.inParamTypes;
                outParams = block.action.desc.outParamTypes;
                if (block.action.desc.exitNames)
                {
                    for (let i: number = 0; i < block.action.desc.exitNames.length; i++)
                    {
                        let exit = new Point(this.blockG);
                        exit.initPoint(this.block.id, i, pointType.OUT_FLOW, linkType.NO_LINK, 175, lenght + outHeight);
                        this.pointArr.push(exit);
                        this.pointXArr.push(175);
                        this.pointyArr.push(lenght + outHeight);
                        outHeight += 30;
                    }
                }
            }
            else if (block.type == lighttool.tsbb.bBlockType.Block_Expr)
            {
                //无出口，无入口
                inParams = block.expr.desc.inParamNames;
                outParams = block.expr.desc.outParamNames;
                //this.blockRect.style.fill = "#ff8800";
                //this.bgFill = "#ff8800";
                this.blockRect.setAttribute("fill-opacity", "0.2");
                this.blockRect.style.stroke = "#ff8800";
                this.blockRect.setAttribute("rx", "20");
                this.blockRect.setAttribute("ry", "20");
                this.titleRect.setAttribute("rx", "20");
                this.titleRect.setAttribute("ry", "20");
            }

            this.titleText.textContent = "" + block.name;

            if (inParams)
            {
                for (let i: number = 0; i < inParams.length; i++)
                {
                    let inParam = new Point(this.blockG);
                    inParam.initPoint(this.block.id, i, pointType.IN_PARAM, linkType.NO_LINK, 5, lenght + inHeight);
                    this.pointArr.push(inParam);
                    this.pointXArr.push(5);
                    this.pointyArr.push(lenght + inHeight);
                    inHeight += 30;
                }
            }
            if (outParams)
            {
                for (let i: number = 0; i < outParams.length; i++)
                {
                    let outParam = new Point(this.blockG);
                    outParam.initPoint(this.block.id, i, pointType.OUT_PARAM, linkType.NO_LINK, 175, lenght + outHeight);
                    this.pointArr.push(outParam);
                    this.pointXArr.push(175);
                    this.pointyArr.push(lenght + outHeight);
                    outHeight += 30;
                }
            }
            lenght += outHeight >= inHeight ? outHeight : inHeight;
            this.blockRect.setAttribute("height", lenght + "");
            this.height = lenght;
            this.width = 200;
            this.updateBloock();
        }

        public updateBloock()
        {
            let x: number = 0;
            let y: number = 0;
            x = this.block.x;   //获取坐标x
            y = this.block.y == null ? 0 : this.block.y;   //获取坐标y
            let title = this.block.name;    //获取title文字
            this.blockRect.style.fill = this.bgFill;
            this.blockRect.setAttribute("class", this.class);
            this.blockRect.setAttribute("x", x + "");
            this.blockRect.setAttribute("y", y + "");
            this.titleRect.setAttribute("x", x + this.titlePoin.x + "");
            this.titleRect.setAttribute("y", y + this.titlePoin.y + "");
            this.titleText.setAttribute("x", x + this.textPoin.x + "");
            this.titleText.setAttribute("y", y + this.textPoin.y + "");
            for (let i: number = 0; i < this.pointArr.length; i++)
            {
                this.pointArr[i].setPoint(x + this.pointXArr[i], y + this.pointyArr[i]);
            }            
        }

        public UpdateScroll(div) {
            if (this.isMouse) {
                var boolXMove = false;
                var boolYMove = false;
                if (this.block.y + this.height > this.background.clientHeight) {
                    div.scrollTop += (this.block.y + this.height) - this.background.clientHeight;
                    boolYMove = true;
                }
                if (this.block.x + this.width > this.background.clientWidth) {
                    div.scrollLeft += (this.block.x + this.width) - this.background.clientWidth;
                    boolXMove = true;
                }
                let height = Math.max(this.background.clientHeight, this.block.y + this.height);
                let width = Math.max(this.background.clientWidth, this.block.x + this.width);
                if (boolXMove) {
                    this.block.x += (this.block.x + this.width) - this.background.clientWidth;
                }
                if (boolYMove) {
                    this.block.y += (this.block.y + this.height) - this.background.clientHeight;
                }
                this.background.setAttribute("width", width + "");
                this.background.setAttribute("height", height + "");
            }
        }

        private exitPoints(x, y): string
        {
            // '0,0 10,0 20,10 10,20 0,20'
            let arrx: number[] = [0, 10, 20, 10, 0];
            let arry: number[] = [0, 0, 10, 20, 20];
            let arr: string = "";
            for (let i: number = 0; i < 5; i++)
            {
                arr += arrx[i] + x + "," + (arry[i] + y) + " ";
            }
            return arr;
        }

        onmousedown(e: MouseEvent)
        {
            //this.background.appendChild(this.blockG);
            this.isMouse = true
            if (e.preventDefault)
            {
                e.preventDefault();
            }
            else
            {
                e.returnValue = false;
            }
            //计算差值
            this.moveX = e.x - this.block.x;
            this.moveY = e.y - this.block.y;
        }
        onmousemove(e: MouseEvent)
        {
            if (this.isMouse) {
                if (e.preventDefault) {
                    e.preventDefault();
                }
                else {
                    e.returnValue = false;
                }
                //更改坐标
                this.block.x = e.x - this.moveX;
                this.block.y = e.y - this.moveY;               
            }
        }
        onmouseup(e: MouseEvent)
        {
            this.isMouse = false;
        }

        public getPoint(type: pointType, id: number): Point
        {
            let i: number = 0;
            if (this.pointArr)
            {
                while (i < this.pointArr.length)
                {
                    if (this.pointArr[i].pointType == type && this.pointArr[i].id == id)
                    {
                        return this.pointArr[i];
                    }
                    i++;
                }
            }
        }

    }


}

